package router

import (
	"github.com/gin-gonic/gin"
	"i18n-template/controller"
	"i18n-template/middleware"
	"i18n-template/table"
	"i18n-template/utils"
)

func UseArticleRouter(group *gin.RouterGroup) {
	group.POST("", middleware.AuthMiddleware(), controller.GenerateArticleController())
	group.GET("", controller.FindArticleController())
	group.PATCH("", middleware.AuthMiddleware(), controller.PatchArticleController())
	group.DELETE("", func(context *gin.Context) {
		a := &table.Article{}
		err := context.ShouldBind(a)
		if err != nil {
			utils.FailResponse(context, "数据绑定失败", err.Error())
			return
		}
		err = a.DeleteArticleByID(a.ID)
		if err != nil {
			utils.FailResponse(context, "删除失败", err.Error())
			return
		}
		utils.SuccessResponse(context, "删除成功!", nil)
	})
}
